package com.zh.note.huawei.twohundred.叠放书籍;

import java.util.*;

/**
 * https://dream.blog.csdn.net/article/details/129741835
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // String input = sc.nextLine();
        String input = "[[20,11],[15,11],[10,10],[9,9]]";
        String[] split = input.replace("[[", "")
                .replace("]]", "")
                .replaceAll("[\\[\\]]", "")
                .split(",");
        List<int[]> list = new ArrayList<>();
        for (int i = 0; i < split.length; i += 2) {
            int[] temp = new int[2];
            temp[0] = Integer.parseInt(split[i]);
            temp[1] = Integer.parseInt(split[i + 1]);
            list.add(temp);
        }
        Collections.sort(list, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[0] == o2[0]) {
                    return o2[1] - o1[1];
                }
                // 降序
                return o2[0] - o1[0];
            }
        });

        int minLen = list.get(0)[0];
        int minWidth = list.get(0)[1];
        int count = 1;
        for (int i = 1; i < list.size(); i++) {
            int[] cur = list.get(i);
            int len = cur[0];
            int width = cur[1];
            if (len < minLen && width < minWidth) {
                minLen = len;
                minWidth = width;
                count++;
            }
        }
        System.out.println(count);

    }
}
